$(function () {
    var ljlx = $("#cghtgl_detail_ljlx").val();
    if (ljlx == 0) {
        $("#ll").show();
        $("#llVal").show();
    } else {
        $("#ll").hide();
        $("#llVal").hide();
    }

    $("#cght_tabs .previewImg").lightbox({
        fitToScreen: true,
        loopImages: true,
        imageClickClose: false,
        disableNavbarLinks: true
    });
    $("span.ljtip").ljDetail($("#cghtgl_detail_ljtip").val(), {
        position: 'top'
    });
    $('#cght_tabs').tabs({
        border: false,
        onSelect: function (title) {
            if (title == "合同文本") {
                // 加载合同文本
                $.ajax({
                    type: "POST",
                    url: $.webPath() + "/htdygl/htwb/htwbDetail",
                    dataType: "html",
                    data: {htdyId: $("[name='htdy.name.id']").val(), htId: $("[name='cght.name.id']").val()},
                    beforeSend: function () {
                        $.messager.progress();
                    },
                    success: function (data) {
                        $.messager.progress("close");
                        $('#htwb_cght_detail_id').html(data);
                        var inputs = document.getElementById("page").getElementsByTagName("input");
                        for (var i = 0; i < inputs.length; i++) {
                            if (null != inputs[i].name) {
                                inputs[i].setAttribute("disabled", "disabled");
                            }
                        }
                        if (data.statusCode == 300) {
                        }
                        if (data.statusCode == 200) {
                        }
                    }
                });
            }
        }
    });

    $("#cght_cgjl_table").datagrid({
        loadFilter: function (data) {
            $.each(data.rows, function () {
                this.cglx = this.cglx == "cgrk" ? "采购入库" : this.cglx == "zddh" ? "直达到货" : this.cglx == "bght" ? "保供采购" : "统配采购";
            })
            return data;
        }
    })

    $("#cghtmx_detail_toolbar a[name='exp']").click(function(){
        var mxUrl = $("#cght_cghtmx_table").attr("url");
        var s = mxUrl.split("?");
        s[0] += "_exp";
        var expUrl = s.join("?");
        window.open(expUrl);
    });

    $("#cght_cghtmx_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#cght_cgjl_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

    $("#cght_fkjl_table").datagrid({
        onLoadSuccess:function(){
            $(".datagrid-htable .datagrid-cell").css('text-align', 'center');
        }
    })

})

function viewZddhCgDetail(id) {
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/htgl/xshtgl/xshtgl_detail?xshtId=" + id,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}

function viewCghtWzjhDetail(wzjhId, wzjhType) {
    $.window({
        title: '详细信息',
        iconCls: 'icon-tip',
        url: $.webPath() + "/jhgl/wzjhgl/wzjhgl_detail?id=" + wzjhId + "&type=" + wzjhType,
        width: 1050,
        height: 500,
        modal: true,
        isMax: false
    })
}